package com.kmxd.ams.core.common.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.kmxd.ams.core.common.constant.ErrorCode;
import com.kmxd.ams.core.exception.BizException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * 管理类型，0:保管期限，1：开放程度，2：涉密档案，3：归档情况
 *
 * @author nickbi
 */
@Getter
@AllArgsConstructor
public enum StatManageTypeEnum {

  /** 保管期限 */
  RETENTION_PERIOD(0, "保管期限"),
  ARCH_OPEN(1, "开放程度"),
  SECURITY(2, "涉密档案"),
  FILLING_TYPE(3, "归档情况"),
  ;

  private Integer code;
  private String desc;

  public static StatManageTypeEnum convert(Integer type) {
    return Arrays.stream(values())
        .filter(x -> x.code.equals(type))
        .findAny()
        .orElseThrow(() -> BizException.instance(ErrorCode.NOT_FOUND, "未找到档案管理状态：" + type));
  }

  @JsonCreator
  public static StatManageTypeEnum getValue(Integer type) {
    return Arrays.stream(values()).filter(x -> Objects.equals(x.code, type)).findAny().orElse(null);
  }
}
